package net.lahuobao.util;

import cn.id5.gboss.businesses.validator.service.app.QueryValidatorServices;
import cn.id5.gboss.businesses.validator.service.app.QueryValidatorServicesProxy;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.ssh.common.Des2;

import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

/**
 * Created by Chris on 2015/4/3.
 */
public class IDVerifyUtil {
    public static boolean querySingle(String name, String idNumber) throws Exception {
        ResourceBundle bundle = PropertyResourceBundle.getBundle("GuoZhengTong");

        QueryValidatorServicesProxy proxy = new QueryValidatorServicesProxy();
        proxy.setEndpoint("http://gboss.id5.cn/services/QueryValidatorServices");
        QueryValidatorServices service = proxy.getQueryValidatorServices();
        //对调用的参数进行加密
        String key = "12345678";
        String userName = Des2.encode(key, bundle.getString("username"));
        String password = Des2.encode(key, bundle.getString("password"));
        System.setProperty("javax.net.ssl.trustStore", "keystore");
        //查询返回结果
        String resultXML = "";
        /*------身份信息核查比对-------*/
        String dataSource = Des2.encode(key, "1A020201");
        //单条
        String param = name + "," + idNumber;
        resultXML = service.querySingle(userName, password, dataSource, Des2.encode(key, param));
        resultXML = Des2.decodeValue(key, resultXML);
        Document doc = null;
        doc = DocumentHelper.parseText(resultXML);
        Element root = doc.getRootElement();// 指向根节点
        Element policeCheckInfos = root.element("policeCheckInfos");
        Element policeCheckInfo = policeCheckInfos.element("policeCheckInfo");
        Element compStatu = policeCheckInfo.element("compStatus");
        int checkStatus = Integer.parseInt(compStatu.getTextTrim());
        if (checkStatus == 3) {
            return true;
        } else {
            return false;
        }
    }
}
